app = angular.module("app", [])
app.controller "mainCtrl", ($scope, $http, flask) ->
    flask("add",
        a: 123
        b: 23
    ).success (data) ->
        console.log data
        return

    flask("getlist",
        n: 5
    ).success (data) ->
        console.log data
        return

    flask("getlist", 5).success (data) ->
        console.log data
        return

    flask("add", 1, 2).success (data) ->
        console.log data
        return

    flask('post_islogin','wkc','123').success (data)->
    	console.log(data);     

    flask('err',5).success (data)->
    	console.log(data)

    return

app.service "flask", ($http) ->
    (cmd, param) ->
        if arguments.length is 2 and angular.isObject(param)
            param = angular.toJson(param)
        else
            param = angular.toJson(Array::slice.call(arguments, 1))
        if param.length > 200 or cmd.indexOf("post") isnt -1
            r = $http.post "/api/" + cmd, param
        else
            r = $http.get "/api/" + cmd + "/" + param
        r.error (data)->
            
        return r
